package com.crm.dao.before_sale;

import com.crm.pojo.Offer;
import com.crm.vo.OfferDetailsVO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface OfferDAO extends CrudRepository<Offer,Long>, JpaSpecificationExecutor<Offer> {
    /**
     * 根据id删除一个销售计划
     * @param planId
     */
    @Query(nativeQuery = true,value = "update OFFER set OFFER_IS_DEL='是' where OF_ID=?1")
    @Modifying
    public void deleteOfferById(Long planId);

    /**
     * 展示一个报价对应的报价明细列表
     * @param offer
     * @return
     */
    @Query("select new com.crm.vo.OfferDetailsVO(o,pr) from OfferDetail o,ProductionDetail pr" +
            " where pr.pid=o.pId and o.offerDetailIsDel='否' and o.offer=?1")
    public List<OfferDetailsVO> getOfferDetailsVOListByOfferId(Offer offer);

    /**
     * 根据id获取一条报价明细
     * @param deId
     * @return
     */
    @Query("select new com.crm.vo.OfferDetailsVO(o,pr) from OfferDetail o,ProductionDetail pr where pr.pid = o.pId and o.deId = ?1 and o.offerDetailIsDel='否'")
    public OfferDetailsVO getOfferDetailById(Long deId);


}
